import { wxRequest } from '../../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: app.globalData.imgUrl,
    status: '2,3',
    date:'', 
    uploadUrl: wx.getStorageSync('uploadUrl'),
    showModal: false,
    tabId:1,
    pageNo: 1,
    hasNextPage: false,
    searchList: [
      { id: 0, value: '手机号' },
      { id: 1, value: '创建人' },
      { id: 2, value: '收货人' },
      { id: 3, value: '代理商' },
      { id: 4, value: '区域经理' },
      { id: 5, value: '店名' }
    ],
    searchType: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  
  onShow:function(){
    this.getlist()
  },


  //tab切换
  handleTab:function(e){
    var tabId = e.currentTarget.dataset.id
    this.setData({
      tabId,
      pageNo: 1
    }) 
    this.getlist()
  },




  //订单详情
  toDtail: function(e){
      wx.navigateTo({
        url: '/pages/menber/mall/detail?id=' + e.currentTarget.dataset.id + '&type=' + this.data.tabId,
      })
  },


  //查询列表
  getlist: function () {
    var url = '/odr/protected/order/findAll'
    // if(this.data.tabId==2){
    //   url = '/odr/protected/orgOrder/findAll'
    // }  
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + url ,
      method: 'POST',
      data:{
        status: this.data.status,
        pageNo: this.data.pageNo,
        kword: this.data.keyword,
        searchType: this.data.searchType || 0
      } 
    }, (res) => {
      let list = res.list;
      if (this.data.pageNo !== 1) {
        list = this.data.list.concat(list);
      }

      this.setData({
        list: list,
        pageNo: res.page.pageNo,
        hasNextPage: res.page.hasNextPage,
      });

    })
  },



  //下拉刷新
  onPullDownRefresh: function () {
    this.refreshData();
    wx.stopPullDownRefresh()
  },

  refreshData: function () {
    this.setData({
      pageNo: 1
    })
    this.getlist();
  },

  //触底时，加载更多
  onReachBottom: function () {
    if (this.data.hasNextPage) {
      this.setData({
        pageNo: this.data.pageNo + 1
      });
      this.getlist();
    }
  },

  //搜索关键词
  seachInputConfirm: function (e) {
    this.setData({
      pageNo: 1,
      keyword: e.detail.value
    })
    this.getlist();
  },

  seachBtn: function () {
    this.setData({
      pageNo: 1,
      keyword: this.data.keyword
    })
    this.getlist();
  },
  
  seachInputVal: function (e) {
    var inputval = e.detail.value;
    console.log(e)
    this.setData({
      keyword: inputval
    })
  },

  //清空
  clearInput: function () {
    this.setData({
      keyword: ''
    })
    this.getlist();
  },



  //********************筛选更多********************
  popupRight: function () {
    this.setData({
      showPopup: true
    })
  },

  popupCancel: function () {
    this.setData({
      showPopup: false
    })
  },

  popupConfirm: function () {
    this.getlist();
    this.popupCancel();
  },

  //选择状态
  checkStatus: function (e) {
    var searchType = e.currentTarget.dataset.id || ''
    var searchValue = e.currentTarget.dataset.value || ''
    this.setData({
      searchType,
      searchValue
    })
  },

  orgNameInput: function (e) {
    var orgName = e.detail.value;
    console.log(orgName, 'orgName')
    this.setData({
      orgName
    })
  },

  clearorgNameInput: function () {
    this.setData({
      orgName: ''
    })
  },

  //********************筛选更多end********************


// pages/menber/mall/order

  toDeliver:function(e){ 
    wx.navigateTo({
      url: '/pages/menber/mall/deliver?id=' + e.currentTarget.dataset.id + '&type=' + this.data.tabId
    })
  }

  
})